//
//  YDAOptionalCell.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/26.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "YDAOptionalCell.h"
#import "YDAOptionalStockModel.h"


@interface  YDAOptionalCell()

//分割线
@property (nonatomic , weak) UIView *lineView;
//股票名称
@property (nonatomic , weak) UILabel *stockName;
//交易所
@property (nonatomic , weak) UILabel *stockPlace;
//股票代码
@property (nonatomic , weak) UILabel *stockCode;
//当前价格
@property (nonatomic , weak) UILabel *currentPrice;
//涨跌幅度
@property (nonatomic , weak) UILabel *upanddown;


@end

@implementation YDAOptionalCell


-(void)setModel:(YDAOptionalStockModel *)model
{
    _model = model;
    
    self.stockName.text = model.name;
    self.stockCode.text = model.code;
    self.currentPrice.text = model.nowPrice;
    self.upanddown.text = model.persentUpDown;
    if (model.priceColor == Price_Up) {
        self.upanddown.textColor = [UIColor colorWithHexString:paleRed];
        self.currentPrice.textColor = [UIColor colorWithHexString:paleRed];
    }else if (model.priceColor == Price_Down){
        self.upanddown.textColor = [UIColor colorWithHexString:leafyGreen];
        self.currentPrice.textColor = [UIColor colorWithHexString:leafyGreen];
    }else{
        self.upanddown.textColor = [UIColor colorWithHexString:paleRed];
        self.currentPrice.textColor = [UIColor colorWithHexString:paleRed];
    }
    
    self.stockPlace.text = model.belongString;
    
}

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *aOptionalCell = @"YDAOptionalCell";
    YDAOptionalCell *cell = [tableView dequeueReusableCellWithIdentifier:aOptionalCell];
    if (cell == nil) {
        cell = [[YDAOptionalCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:aOptionalCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.backgroundColor = [UIColor whiteColor];
        [self lineView];
        [self stockName];
        [self stockCode];
        [self stockPlace];
        [self currentPrice];
        [self upanddown];
        
    }
    return self;
}

-(UIView *)lineView
{
    if (_lineView == nil) {
        UIView *lineView = [[UIView alloc] init];
        [self.contentView addSubview:lineView];
        lineView.backgroundColor = NumberColor(247, 247, 247);
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self);
            make.height.equalTo(@1);
            //            make.left.equalTo(self).offset(20);
            //            make.right.equalTo(self).offset(-20);
        }];
        _lineView = lineView;
    }
    return _lineView;
}
-(UILabel *)stockName
{
    if (_stockName == nil) {
        UILabel *stockName = [[UILabel alloc] init];
        [self.contentView addSubview:stockName];
        stockName.textColor = NumberColor(30, 36, 46);
        stockName.font = [UIFont systemFontOfSize:font16ScreenWRate * LKScreenW];
        stockName.textAlignment = NSTextAlignmentLeft;
        stockName.text = @"万科a";
        [stockName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(rate375(14.5));
            make.bottom.equalTo(self.mas_centerY).offset(8);
        }];
        _stockName = stockName;
    }
    return _stockName;
}
-(UILabel *)stockCode
{
    if (_stockCode == nil) {
        UILabel *stockCode = [[UILabel alloc] init];
        [self.contentView addSubview:stockCode];
        stockCode.textColor = NumberColor(173, 179, 193);
        stockCode.font = [UIFont systemFontOfSize:font10ScreenWRate * LKScreenW];
        stockCode.textAlignment = NSTextAlignmentLeft;
        stockCode.text = @"sz000001";
        [stockCode mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.stockName);
            make.top.equalTo(self.stockName.mas_bottom);
        }];
        _stockCode = stockCode;
    }
    return _stockCode;
}
-(UILabel *)stockPlace
{
    if (_stockPlace == nil) {
        UILabel *stockPlace = [[UILabel alloc] init];
        [self.contentView addSubview:stockPlace];
        stockPlace.textColor = [UIColor whiteColor];
        stockPlace.font = [UIFont systemFontOfSize:font10ScreenWRate * LKScreenW];
        stockPlace.textAlignment = NSTextAlignmentCenter;
        stockPlace.text = @"sz";
        stockPlace.backgroundColor = NumberColor(226, 96, 96);
        [stockPlace mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.stockName.mas_right).offset(rate375(10));
            make.centerY.equalTo(self.stockName);
            make.width.equalTo(@(rate375(16)));
        }];
        stockPlace.layer.cornerRadius = 2;
        stockPlace.layer.masksToBounds = YES;
        _stockPlace = stockPlace;
    }
    return _stockPlace;
}

-(UILabel *)currentPrice
{
    if (_currentPrice == nil) {
        UILabel *currentPrice = [[UILabel alloc] init];
        [self.contentView addSubview:currentPrice];
        currentPrice.textColor = NumberColor(30, 36, 46);
        currentPrice.font = [UIFont systemFontOfSize:font16ScreenWRate *LKScreenW];
        currentPrice.textAlignment = NSTextAlignmentCenter;
        currentPrice.text = @"27.25";
        [currentPrice mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self);
        }];
        _currentPrice = currentPrice;
    }
    return _currentPrice;
}
-(UILabel *)upanddown
{
    if (_upanddown == nil) {
        UILabel *upanddown = [[UILabel alloc] init];
        [self.contentView addSubview:upanddown];
        upanddown.textColor = NumberColor(71, 194, 51);
        upanddown.font = [UIFont systemFontOfSize:font16ScreenWRate *LKScreenW];
        upanddown.textAlignment = NSTextAlignmentCenter;
        upanddown.text = @"-1.92%";
        [upanddown mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.right.equalTo(self).offset(-rate375(20));
        }];
        _upanddown = upanddown;
    }
    return _upanddown;
}




@end
